package com.dianrui.operation.dialog.FlycoDialog;

import android.app.Dialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.dianrui.operation.R;
import com.dianrui.operation.interfaces.OnAskDialogCallBack;


public class UpdateAppDialog {

    public static void createStartCarDialog(final Context context, String title, String content,String isUpdate,final OnAskDialogCallBack onAskDialogCallBack) {
        final Dialog dialog = new Dialog(context, R.style.RcDialog);
        View view = LayoutInflater.from(context).inflate(R.layout.update_dialog, null);
        TextView tv_title =view.findViewById(R.id.tv_title);
        TextView tv_content =view.findViewById(R.id.tv_update_info);
        final TextView tv_ignore = view.findViewById( R.id.tv_ignore);
        final ImageView iv_close = view.findViewById( R.id.iv_close);
        final TextView btn_update = view.findViewById(R.id.btn_update);
        final LinearLayout updateCloseLayout=view.findViewById(R.id.update_close_layout);
        tv_title.setText(title);
        tv_content.setText(content);
        if (isUpdate.equals("1")) {
            updateCloseLayout.setVisibility(View.GONE);
            tv_ignore.setVisibility(View.GONE);
        }else {
            updateCloseLayout.setVisibility(View.VISIBLE);
            tv_ignore.setVisibility(View.VISIBLE);
        }
        tv_ignore.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onAskDialogCallBack != null) {
                    onAskDialogCallBack.onCancel(dialog);
                }
            }
        });
        btn_update.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onAskDialogCallBack != null) {
                    onAskDialogCallBack.onokey(dialog);
                }
            }
        });
        iv_close.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
        dialog.setCanceledOnTouchOutside(false);
        dialog.setContentView(view);
        dialog.show();

    }
}
